﻿@model GPS.ENTITYS.ViewModelDKH_LH1
@using PagedList.Mvc;
@using GPS.Helpers;
@{
    ViewBag.Title = "Lịch học";
}

<style type="text/css">
    .table-condensed thead {
        background-color: rgba(243, 112, 44, 1);
        color: white;
    }

        .table-condensed thead th {
            /*background: rgba(243, 112, 44, 1);*/
            color: #FCFFFF;
            cursor: pointer;
            white-space: nowrap;
            padding: 3px 6px 5px;
            border: 1px solid #FF6600;
            background: #94b6e8 url(../fonts/bgr_title_So.gif) repeat-x center top;
            overflow: hidden;
            font-weight: bold;
            text-align: center;
        }

        .table-condensed thead tr th {
            border: 1px solid #FF6600;
        }
</style>

<div class="container fdb-div-content fdb-div-corner-all">
    <h3 class="text-center fdb-title-search-form">Theo dõi quản lý lịch học</h3>
    <div class="row">

        <div class="list-group">
            <fieldset class="fs_body">
                <legend class="head_title">Điều Kiện Tìm Kiếm</legend>
                <div class="criteria_search">
                    <div class="row margin-top-05">
                        <div class="col-md-2 control-label">
                            Đơn vị đào tạo
                        </div>
                        <div class="col-md-4">
                            @Html.DropDownListFor(model => model.KH_LH_DVGTVT_MA, (SelectList)ViewBag.DVGTVT_MAs, "---Lựa chọn--", new { @class = "form-control", @id = "DVGTVT_MA_dll" })
                        </div>
                        <div class="col-md-2 control-label">
                            Khóa đào tạo
                        </div>
                        <div class="col-md-4">
                            @Html.DropDownListFor(model => model.KH_LH_KH_MA, (SelectList)ViewBag.KH_MAs, string.Empty, new {  @title = "Vui lòng chọn khóa học...", @id = "KH_MA_dll", @style = "font-weight:bold;width:300px" })
                        </div>
                    </div>

                    <div class="row margin-top-05">
                        <div class="col-md-2 control-label" style="display:none">
                            Phương tiện
                        </div>
                        <div class="col-md-4" style="display:none">
                            @Html.DropDownListFor(model => model.KH_LH_PT_BIENSO, (SelectList)ViewBag.DEFAULT_VALUE_DDL, string.Empty, new { @class = "form-control", @id = "KH_LH_PT_BIENSO" })

                        </div>
                        <div class="col-md-2 control-label">
                            Giảng viên
                        </div>
                        <div class="col-md-4">
                            @Html.DropDownListFor(model => model.KH_LH_GV_MA, (SelectList)ViewBag.DEFAULT_VALUE_DDL, string.Empty, new { @class = "form-control", @id = "KH_LH_GV_MA" })
                         
                        </div>
                        
                    </div>

                    <div class="row margin-top-05">

                        <div class="col-md-2 control-label">
                            Hạng đào tạo
                        </div>
                        <div class="col-md-4">
                            @Html.DropDownListFor(model => model.HANGDT_MA, (SelectList)ViewBag.HANGDT_MAs, string.Empty, new { @class = "form-control", @id = "HANGDT_MA_dll" })
                        </div>
                    </div>

                </div>

                <div class="row margin-top-05 btn_search">
                    <button type="button" class="btn btn-primary btn-sm" id="btnSearch">
                        <span class="glyphicon glyphicon-search"></span> Tìm kiếm
                    </button>
                    @Html.NoEncodeActionLink("<span class='glyphicon glyphicon-plus'></span> Thêm mới", "Thêm mới", "Create", "GPS_LichHoc_LT", null, htmlAttributes: new { data_modal = "", @class = "btn btn-primary btn-sm" })
                    @*<div class="pull-right col-lg-1">
                            <a class="btn btn-success" data-modal="" href="/GPS_LichHoc_LT/Create" id="btnCreate">
                                <span class="glyphicon glyphicon-plus"></span>
                            </a>
                        </div>*@
                </div>
            </fieldset>
        </div>


        <div class="row">
            <fieldset class="fs_body">
                <legend class="head_title">Kết quả tìm kiếm</legend>


                @Html.Action("List")

            </fieldset>
        </div>
    </div>
</div>

<div id="wait" style="display: none; position:absolute; top: 10%; right: 10%; padding: 2px; z-index: 99999">
    <img src="~/fonts/images/loading16.gif" width="65" height="65" />
</div>
<!-- Modal -->

<div id='myModal' class='modal fade in'>
    <div class="modal-dialog">
        <div class="modal-content">
            <div id='myModalContent'></div>
        </div>
    </div>
</div>

<!-- Modal Start here-->
<div class="modal fade bs-example-modal-sm" id="pleaseWaitDialog" tabindex="-1"
     role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-sm" style="top:50%">
        <div class="modal-content" style="margin: 0 auto;width:300px">
            <div class="modal-header">
                <h4 class="modal-title">
                    <span class="glyphicon glyphicon-time">
                    </span>Đang xử lý...
                </h4>
            </div>
            <div class="modal-body">
                <div class="progress">
                    <div class="progress-bar progress-bar-info
                    progress-bar-striped active"
                         style="width: 100%">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<link href="~/dist/css/bootstrap-select.css" rel="stylesheet" />
<script src="~/dist/js/bootstrap-select.js"></script>

<link href="~/Scripts/select2.css" rel="stylesheet" />
<link href="~/Scripts/select2.min.css" rel="stylesheet" />
<script src="~/Scripts/select2.js"></script>
<!-- Modal ends Here -->

<script language="javascript" type="text/javascript">

    toastr.options = {
        "debug": false,
        "positionClass": "toast-top-right",
        "fadeIn": 500,
        "fadeOut": 2000,
        "timeOut": 1000,
        "extendedTimeOut": 1000

    }

    $(function () {
        $.ajaxSetup({ cache: false });
        $("body").on('click', 'a[data-modal]', function (e) {
            //$("#dvLoading").attr("style", "display:block; height: 100px;width: 100px;position: fixed;left: 50%;top: 50%;margin: -25px 0 0 -25px;z-index: 1000;");
            $('#myModalContent').empty();
            $('#pleaseWaitDialog').modal('show');

            $('#myModalContent').load(this.href, function () {
                $('#myModal').modal({
                    keyboard: true
                }, 'show');
                //$("#dvLoading").attr("style", "display:none; height: 100px;width: 100px;position: fixed;left: 50%;top: 50%;margin: -25px 0 0 -25px;z-index: 1000;");

                $('#pleaseWaitDialog').modal('hide');

            });
            return false;
        });

        //$('.selectpicker').selectpicker({
        //    liveSearch: true,
        //    showSubtext: true
        //});
    });

    $(document).ready(function () {

        var pageSize = 20;
        var optionListUrl = '@Url.Action("Select2KH_MA_LH", "GPS_Ajax")';

        $('#KH_MA_dll').select2(
                {
                    ajax: {
                        delay: 50,
                        url: optionListUrl,
                        dataType: 'json',

                        data: function (params) {
                            /// params.page = params.page || 1;
                            return {
                                searchTerm: params.term,// + "#" + $("#DVGTVT_MA").val(),
                                dvgtvt_ma: $("#DVGTVT_MA_dll").val()
                                //pageNumber: params.page results: JSON.parse(data)
                            };
                        },
                        processResults: function (data, params) {

                            return {
                                results: data.Results
                            };
                        }
                    },
                    placeholder: "-- Chọn khóa học --",
                    minimumInputLength: 2,
                    allowClear: true,
                    language: { inputTooShort: function () { return 'Nhập lớn hơn 2 ký tự để tìm kiếm khóa học'; } }
                });

        //dropdownlist:
        $("#KH_MA_dll").on("change", function () {
            // lstBoxPhuongTien
            var position = $(this).position();

            $("#wait").attr("style", "display:block;position:absolute;top:40%;left:50%;padding:2px; z-index:99999");
            @*$.ajax({
                url: '@Url.Action("getPT_IN_KH_MAs2", "GPS_LichHoc_TH")',
                type: 'post',
                data: {
                    Ma_KH: $(this).val()
                }
            }).done(function (response) {
                // update district by province
                var a = '<option value></option>' + response;   // defaut value
                $("#KH_LH_PT_BIENSO").html(a);
                $("#wait").attr("style", "display:none;position:absolute;top:40%;left:50%;padding:2px; z-index:99999");
            });*@

            $.ajax({
                url: '@Url.Action("getGV_IN_KH_MAs", "GPS_LichHoc_TH")',
                type: 'post',
                data: {
                    Ma_KH: $(this).val()
                }
            }).done(function (response) {
                // update district by province
                var a = '<option value></option>' + response;   // defaut value
                $("#KH_LH_GV_MA").html(a);
                $("#wait").attr("style", "display:none;position:absolute;top:40%;left:50%;padding:2px; z-index:99999");
            });


        });

        $("#KH_LH_PT_BIENSO").on("change", function () {
            // lstBoxPhuongTien
            var position = $(this).position();

            $("#wait").attr("style", "display:block;position:absolute;top:40%;left:50%;padding:2px; z-index:99999");


            $.ajax({
                url: '@Url.Action("GPS_GET_GV_IN_PT", "GPS_LichHoc_LT")',
                type: 'post',
                data: {
                    Ma_KH: $("#KH_MA_dll").val(),
                    Ma_PT: $(this).val()
                },
            }).done(function (response) {
                // update district by province
                var a = '<option value></option>' + response;   // defaut value
                $("#KH_LH_GV_MA").html(a);
                $("#wait").attr("style", "display:none;position:absolute;top:40%;left:50%;padding:2px; z-index:99999");
            });



        });


        //search data
        $(document).on("click", "#btnSearch", function () {

            $('#pleaseWaitDialog').modal('show');
            var data = {
                KH_LH_DVGTVT_MA: $("#DVGTVT_MA_dll").val(),
                KH_LH_KH_MA: $("#KH_MA_dll").val(),
                KH_LH_GV_MA: $("#KH_LH_GV_MA").val(),
                KH_LH_PT_BIENSO: $("#KH_LH_PT_BIENSO").val(),
                HANGDT_MA: $("#HANGDT_MA_dll").val()
            }

            var _url = '/GPS_LichHoc_LT/List?page=1' + '&KH_LH_DVGTVT_MA=' + data.KH_LH_DVGTVT_MA + '&KH_LH_KH_MA=' + data.KH_LH_KH_MA + '&KH_LH_GV_MA=' + data.KH_LH_GV_MA + '&KH_LH_PT_BIENSO=' + data.KH_LH_PT_BIENSO + '&HANGDT_MA=' + data.HANGDT_MA;
            $.ajax({
                url: _url,
                type: "GET",
                cache: false,
                success: function (result) {

                    $('#content').html(result);

                    $('#pleaseWaitDialog').modal('hide');
                },
                error: function () {
                    $('#msg').html('<div class="failed">Error! Please try again.</div>');

                    $('#pleaseWaitDialog').modal('hide');
                }
            });

        });

        //Pagging
        $(document).on("click", "#contentPager a[href]", function () {
            $('#pleaseWaitDialog').modal('show');
            var _url = $(this).attr("href");
            var _pagenumber = _url.split('=')[1];
            //alert(_pagenumber);
            var data = {
                KH_LH_DVGTVT_MA: $("#DVGTVT_MA_dll").val(),
                KH_LH_KH_MA: $("#KH_MA_dll").val(),
                KH_LH_GV_MA: $("#KH_LH_GV_MA").val(),
                KH_LH_PT_BIENSO: $("#KH_LH_PT_BIENSO").val(),
                HANGDT_MA: $("#HANGDT_MA_dll").val(),
                Page: _pagenumber
            }

            $.ajax({
                url: $(this).attr("href") + '&KH_LH_DVGTVT_MA=' + data.KH_LH_DVGTVT_MA + '&KH_LH_KH_MA=' + data.KH_LH_KH_MA + '&KH_LH_GV_MA=' + data.KH_LH_GV_MA + '&KH_LH_PT_BIENSO=' + data.KH_LH_PT_BIENSO + '&HANGDT_MA=' + data.HANGDT_MA + '&Page=' + data.Page,
                type: 'GET',
                cache: false,
                success: function (result) {
                    $('#content').html(result);

                    $('#pleaseWaitDialog').modal('hide');
                },
                error: function () {
                    $('#msg').html('<div class="failed">Error! Please try again.</div>');

                    $('#pleaseWaitDialog').modal('hide');
                }
            });
            return false;
        });


        //Create
        $("body").on('submit', '#saveFormCreate', function (e) {

            e.preventDefault();

            var l = $("#ulGroup_PT_GV li").length;
            //alert(l);
            if (l == 0)
            {


                if ($("#ddlGV_MA").val() == null || $("#ddlGV_MA").val() == '')
                {

                    alert($("#ddlGV_MA").val());
                    $("#lblValidateKH_LH_GV_MA").attr("style", "display:block;color:#b94a48");
                    $("#ddlGV_MA").attr("style", "border:solid 1px #b94a48");
                    $('#pleaseWaitDialog').modal('hide');
                    return false;
                }
            }

            $('#pleaseWaitDialog').modal('show');

            $.ajax({
                url: '/GPS_LichHoc_LT/Create',
                type: 'POST',
                data: $(this).serialize(),
                dataType: 'json',
                success: function (data) {

                    var _pagenumber = $(".active a").text();
                    var data1 = {
                        KH_LH_DVGTVT_MA: $("#DVGTVT_MA_dll").val(),
                        KH_LH_KH_MA: $("#KH_MA_dll").val(),
                        KH_LH_GV_MA: $("#KH_LH_GV_MA").val(),
                        KH_LH_PT_BIENSO: $("#KH_LH_PT_BIENSO").val(),
                        HANGDT_MA: $("#HANGDT_MA_dll").val(),
                        Page: _pagenumber
                    }
                    var _url = '/GPS_LichHoc_LT/List?page=' + _pagenumber + '&KH_LH_DVGTVT_MA=' + data1.KH_LH_DVGTVT_MA + '&KH_LH_KH_MA=' + data1.KH_LH_KH_MA + '&KH_LH_GV_MA=' + data1.KH_LH_GV_MA + '&KH_LH_PT_BIENSO=' + data1.KH_LH_PT_BIENSO + '&HANGDT_MA=' + data1.HANGDT_MA;
                    $.ajax({
                        url: '/GPS_LichHoc_LT/List', //_url
                        type: 'GET',
                        data: data1,
                        cache: false,
                        success: function (result) {
                            $('#content').html(result);

                            toastr.success('Cập nhật thành công!', 'thông báo');


                        }
                    });

                    var v = $("#ddlKH_LH_TUAN").val();
                    $("#ddlKH_LH_TUAN").val((parseInt(v)+1).toString());
                    // alert(v);
                    $.ajax({
                        url: '@Url.Action("GPS_GET_DATE_BY_WEEK", "GPS_LichHoc_LT")',
                        type: 'POST',
                        traditional: true,
                        data: {
                            Week: parseInt(v)+1,
                            StartDate: $('#txtNGAY_KG').val(),
                            EndDate: $('#txtNGAY_BG').val()
                        },
                        dataType: 'json',
                        success: function (data) {
                            $("#txtKH_LH_TUNGAY").val(data.dateranges.StrStartDate);
                            $("#txtKH_LH_DENNGAY").val(data.dateranges.StrEndDate);

                            // $("#wait").attr("style", "display:none;position:absolute;top:25%;left:50%;padding:2px; z-index:99999");
                        },
                        error: function () {

                            alert("Lỗi kết nối với server!");
                            // $("#wait").attr("style", "display:none;position:absolute;top:20%;left:50%;padding:2px; z-index:99999");

                        }
                    });
                    $('#pleaseWaitDialog').modal('hide');
                    return false;
                },
                error: function () {
                    $('#msg').html('<div class="failed">Error! Please try again.</div>');

                    $('#pleaseWaitDialog').modal('hide');
                }
            });
        });

        ////btnCloseCreate
        //$("body").on('Click', '#btnCloseCreate', function (e) {
        //    e.preventDefault();
        //    $('#myModal').modal('toggle');
        //    $('#myModalContent').empty();

        //    return false;

        //});

        //Edit
        $("body").on('submit', '#saveFormEdit', function (e) {
            e.preventDefault();
            $('#pleaseWaitDialog').modal('show');

            $.ajax({
                url: '/GPS_LichHoc_LT/Edit',
                type: 'POST',
                data: $(this).serialize(),
                dataType: 'json',
                success: function (data) {

                    var _pagenumber = $(".active a").text();

                    var data1 = {
                        KH_LH_DVGTVT_MA: $("#DVGTVT_MA_dll").val(),
                        KH_LH_KH_MA: $("#KH_MA_dll").val(),
                        KH_LH_GV_MA: $("#KH_LH_GV_MA").val(),
                        KH_LH_PT_BIENSO: $("#KH_LH_PT_BIENSO").val(),
                        HANGDT_MA: $("#HANGDT_MA_dll").val(),
                        Page: _pagenumber
                    }
                    var _url = '/GPS_LichHoc_LT/List?page=' + _pagenumber + '&KH_LH_DVGTVT_MA=' + data1.KH_LH_DVGTVT_MA + '&KH_LH_KH_MA=' + data1.KH_LH_KH_MA + '&KH_LH_GV_MA=' + data1.KH_LH_GV_MA + '&KH_LH_PT_BIENSO=' + data1.KH_LH_PT_BIENSO + '&HANGDT_MA=' + data1.HANGDT_MA;
                    $.ajax({
                        url: '/GPS_LichHoc_LT/List', //_url
                        type: 'GET',
                        data: data1,
                        cache: false,
                        success: function (result) {
                            $('#content').html(result);

                            toastr.success('Cập nhật thành công!', 'thông báo');

                            $('#pleaseWaitDialog').modal('hide');
                        }
                    });
                    return false;
                },
                error: function () {
                    $('#msg').html('<div class="failed">Error! Please try again.</div>');

                    $('#pleaseWaitDialog').modal('hide');
                }
            });
        });

        //Delete
        $("body").on('submit', '#saveFormDelete', function (e) {
            e.preventDefault();
            $('#pleaseWaitDialog').modal('show');

            $.ajax({
                url: '/GPS_LichHoc_LT/Delete/' + $("#ID").val(),
                type: 'POST',
                data: $(this).serialize(),
                dataType: 'json',
                success: function (data) {

                    var _pagenumber = $(".active a").text();

                    var data1 = {
                        KH_LH_DVGTVT_MA: $("#DVGTVT_MA_dll").val(),
                        KH_LH_KH_MA: $("#KH_MA_dll").val(),
                        KH_LH_GV_MA: $("#KH_LH_GV_MA").val(),
                        KH_LH_PT_BIENSO: $("#KH_LH_PT_BIENSO").val(),
                        HANGDT_MA: $("#HANGDT_MA_dll").val(),
                        Page: _pagenumber
                    }
                    var _url = '/GPS_LichHoc_LT/List?page=' + _pagenumber + '&KH_LH_DVGTVT_MA=' + data1.KH_LH_DVGTVT_MA + '&KH_LH_KH_MA=' + data1.KH_LH_KH_MA + '&KH_LH_GV_MA=' + data1.KH_LH_GV_MA + '&KH_LH_PT_BIENSO=' + data1.KH_LH_PT_BIENSO + '&HANGDT_MA=' + data1.HANGDT_MA;
                    $.ajax({
                        url: '/GPS_LichHoc_LT/List', //_url
                        type: 'GET',
                        data: data1,
                        cache: false,
                        success: function (result) {
                            $('#content').html(result);

                            toastr.success('Xóa thành công!', 'thông báo');
                            $('#myModal').modal('hide');

                            $('#pleaseWaitDialog').modal('hide');
                        }
                    });
                    return false;
                },
                error: function () {
                    $('#msg').html('<div class="failed">Error! Please try again.</div>');

                    $('#pleaseWaitDialog').modal('hide');
                }
            });
        });

    });


        //$('#txtKH_LH_TUNGAY').datepicker({
        //    changeMonth: true,
        //    changeYear: true,

        //    dateFormat: 'dd/mm/yy'
        //});



</script>


